home *** CD-ROM | disk | FTP | other *** search
- /* $Id: timer.c,v 1.8 1999/07/24 04:55:33 chrisf Exp $ */
-
- /*
- Hot Date - A DatebookDB displayer for the PalmPilot
- Copyright (C) 1999 Chris Faherty
-
- This program is free software; you can redistribute it and/or
- modify it under the terms of the GNU General Public License
- as published by the Free Software Foundation; either version 2
- of the License, or (at your option) any later version.
-
- This program is distributed in the hope that it will be useful,
- but WITHOUT ANY WARRANTY; without even the implied warranty of
- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- GNU General Public License for more details.
-
- You should have received a copy of the GNU General Public License
- along with this program; if not, write to the Free Software
- Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
- */
-
- #include <Pilot.h>
- #include "callback.h"
- #include "hotdate.h"
- #include "hotdateRsc.h"
- #include "timer.h"
-
- /*
- * Static function prototypes
- */
- static Boolean ShowAlarmHandleEvent(EventPtr event);
-
- void SetTimeOfNextAlarm(ULong alarmTime, DWord ref)
- {
- UInt cardNo;
- LocalID dbID;
- DmSearchStateType searchInfo;
-
- if (DmGetNextDatabaseByTypeCreator(true, &searchInfo,
- sysFileTApplication, MainAppID, true, &cardNo, &dbID)) return;
-
- AlmSetAlarm(cardNo, dbID, ref, alarmTime, 0);
- }
-
- ULong GetTimeOfNextAlarm(DWordPtr ref)
- {
- UInt cardNo;
- LocalID dbID;
- DmSearchStateType searchInfo;
-
- if (DmGetNextDatabaseByTypeCreator(true, &searchInfo,
- sysFileTApplication, MainAppID, true, &cardNo, &dbID)) return 0;
-
- return AlmGetAlarm(cardNo, dbID, ref);
- }
-
- static Boolean ShowAlarmHandleEvent(EventPtr event)
- {
- FormPtr frm;
- Boolean result=false;
-
- CALLBACK_PROLOGUE
-
- /*
- * We don't want to allow an other application to be launched
- * while an alarm is displayed, so we intercept appStop events.
- * All other event are handled by FrmDoDialog.
- */
- if (event->eType == appStopEvent) result = true;
-
- /*
- * I don't like the launch silk-screen button being pressed
- * during the alarm dialog. It doesn't do anything and is
- * quite confusing to the user.
- */
- else if ((event->eType == keyDownEvent) &&
- (event->data.keyDown.modifiers & commandKeyMask) &&
- (event->data.keyDown.chr == launchChr)) result = true;
-
- else if (event->eType == frmUpdateEvent) {
- frm = FrmGetActiveForm();
- FrmDrawForm(frm);
- }
-
- CALLBACK_EPILOGUE
-
- return result;
- }
-
- void DisplayAlarm(void)
- {
- FormPtr frm;
- FormPtr curForm;
- DWord ref;
-
- frm = FrmInitForm(AlarmForm);
-
- curForm = FrmGetActiveForm();
- if (curForm) FrmSetActiveForm(frm);
-
- /* Set the event handler for the alarm dialog. */
- FrmSetEventHandler(frm, ShowAlarmHandleEvent);
- FrmDrawForm(frm);
-
- /* Display the alarm dialog. */
- FrmDoDialog(frm);
-
- FrmDeleteForm(frm);
-
- FrmSetActiveForm(curForm);
-
- /*
- * Cancel any scheduled repeating alarm sounds.
- */
- if (GetTimeOfNextAlarm(&ref) && (ref > 0)) SetTimeOfNextAlarm(0, 0);
- }
-
- void AlarmTriggered(SysAlarmTriggeredParamType * cmdPBP)
- {
- ULong alarmTime;
- DWord ref;
-
- alarmTime = 0;
- ref = 0;
-
- /*
- * The reference value contains the number of times the alarm has
- * sounded for an event.
- */
- if (cmdPBP->ref == 0) {
- /*
- * This is the first alarm. Since we don't disable the display
- * we should expect a sysAppLaunchCmdDisplayAlarm shortly.
- */
- /* Play the alarm sound. */
- SndPlaySystemSound(sndAlarm);
- } else {
- /*
- * Pass the following value to the alarm manager, this will be
- * removed from the alarm table and the display notification will
- * NOT be generated for it. We don't want display notifications
- * on repeat sounds.
- */
- cmdPBP->purgeAlarm = true;
- /* Play the alarm sound. */
- SndPlaySystemSound(sndAlarm);
- }
-
- if (cmdPBP->ref < 2) {
- alarmTime = TimGetSeconds()+30;
- ref = cmdPBP->ref+1;
- }
-
- if (alarmTime) SetTimeOfNextAlarm(alarmTime, ref);
- }
-